<?php
function loadPage($mod){
	$needFlush=true;
	if(PAGE_CACHE_ON){
		if (!is_dir(PAGE_CACHE_FILE_PATH.$mod)) {
			mkdir(PAGE_CACHE_FILE_PATH.$mod);
		}
     }
    $content="";

	if($mod=="download"||$mod=="detail"){
		$content=loadSoftwarePage($mod);
	}else if($mod=="categories"||$mod=="child-category"){
		$content=loadCate($mod);
	}else if($mod=="keywordlist"){
		$content=loadKeyword();
	}else{
		$content=loadIndex();
	}
	return $content;
}
function loadKeyword(){
	$keyword=$_GET['keyword'];
	$content=@file_get_contents(SERVER_ROOT."keywordlist.php?page=1&keyword=".$keyword);	
	saveCache(PAGE_CACHE_FILE_PATH."/keywordlist/".$keyword.".html",$content);
	return	$content;
}

function loadIndex(){
	$content=@file_get_contents(SERVER_ROOT."index2.php");	
	saveCache(PAGE_CACHE_FILE_PATH."/index.html",$content);
	return	$content;
}

function loadCate($mod){
	$name=$_GET['name'];
	//echo $_SERVER['REQUEST_URI'];
	$url=SERVER_ROOT.$mod.".php?name=".urlencode($name);
	$content=@file_get_contents($url);	
	saveCache(PAGE_CACHE_FILE_PATH.$mod."/".$name.".html",$content);
	return $content;
}


function loadSoftwarePage($mod){
	$id=$_GET['id'];
	$content=@file_get_contents(SERVER_ROOT.$mod.".php?id=".$id);	
	saveCache(PAGE_CACHE_FILE_PATH.$mod."/".$id.".html",$content);
	return $content;
}

function saveCache($path,$content){
       $handle = fopen($path, 'w');
       if (!$handle || !fwrite($handle, $content))
        {
                return false;
        }
        fclose($handle);
}
?>
